﻿using System.Data.SQLite;
using DVDTek_Data_Object.Accessor;

namespace DVDTek_Data_Object.DataObject
{
    public class VideoDataObject
    {
        #region Members
        private int id;
        private string synopsis;
        private int period;
        private string main_language;
        private string other_language;
        private string subtitle;
        private string video_format;
        private string audio_format;
        private string resolution;
        private int frequency;
        private int size;

        public int Id
        {
            get { return this.id; }
        }
        public string Synopsis
        {
            get { return this.synopsis; }
            set { this.synopsis = value; }
        }
        public int Period
        {
            get { return this.period; }
            set { this.period = value; }
        }
        public string MainLanguage
        {
            get { return this.main_language; }
            set { this.main_language = value; }
        }
        public string OtherLanguage
        {
            get { return this.other_language; }
            set { this.other_language = value; }
        }
        public string Subtitle
        {
            get { return this.subtitle; }
            set { this.subtitle = value; }
        }
        public string VideoFormat
        {
            get { return this.video_format; }
            set { this.video_format = value; }
        }
        public string AudioFormat
        {
            get { return this.audio_format; }
            set { this.audio_format = value; }
        }
        public string Resolution
        {
            get { return this.resolution; }
            set { this.resolution = value; }
        }
        public int Frequency
        {
            get { return this.frequency; }
            set { this.frequency = value; }
        }
        public int Size
        {
            get { return this.size; }
            set { this.size = value; }
        }
        #endregion

        #region Constructors
        public VideoDataObject()
        {
            this.id = -1;
            this.Synopsis = string.Empty;
            this.Period = 0;
            this.MainLanguage = string.Empty;
            this.OtherLanguage = string.Empty;
            this.Subtitle = string.Empty;
            this.VideoFormat = string.Empty;
            this.AudioFormat = string.Empty;
            this.Resolution = string.Empty;
            this.Frequency = 0;
            this.Size = 0;
        }
        public VideoDataObject(string synopsis, int period, string main_language, string other_language,
            string subtitle, string video_format, string audio_format, string resolution, int frequency, int size)
        {
            this.id = -1;
            this.Synopsis = synopsis;
            this.Period = period;
            this.MainLanguage = main_language;
            this.OtherLanguage = other_language;
            this.Subtitle = subtitle;
            this.VideoFormat = video_format;
            this.AudioFormat = audio_format;
            this.Resolution = resolution;
            this.Frequency = frequency;
            this.Size = size;
        }
        public VideoDataObject(int id, string synopsis, int period, string main_language, string other_language,
            string subtitle, string video_format, string audio_format, string resolution, int frequency, int size)
        {
            this.id = id;
            this.Synopsis = synopsis;
            this.Period = period;
            this.MainLanguage = main_language;
            this.OtherLanguage = other_language;
            this.Subtitle = subtitle;
            this.VideoFormat = video_format;
            this.AudioFormat = audio_format;
            this.Resolution = resolution;
            this.Frequency = frequency;
            this.Size = size;
        }
        #endregion

        public VideoDataObject Copy()
        {
            return new VideoDataObject(
                this.Id, this.Synopsis, this.Period, this.MainLanguage, this.OtherLanguage, this.Subtitle,
                this.VideoFormat, this.AudioFormat, this.Resolution, this.Frequency, this.Size);
        }

        public void Update()
        {
            if (this.id == -1)
                this.id = VideoAccessor.Instance.Insert(
                    this.Synopsis, this.Period, this.MainLanguage, this.OtherLanguage, this.Subtitle,
                    this.VideoFormat, this.AudioFormat, this.Resolution, this.Frequency, this.Size);
            else
                VideoAccessor.Instance.Update(
                    this.Id, this.Synopsis, this.Period, this.MainLanguage, this.OtherLanguage, this.Subtitle,
                    this.VideoFormat, this.AudioFormat, this.Resolution, this.Frequency, this.Size);
        }

        public void Delete()
        {
            if (this.id != -1)
            {
                VideoAccessor.Instance.Delete(this.Id);
                this.id = -1;
            }
        }

        public static VideoDataObject GetVideoDataObject(int id)
        {
            return VideoAccessor.Instance.Select(id);
        }
    }
}
